package task03;

import java.util.HashMap;
import java.util.Map;

public class Tracker {
    private Map<String, Point> map;

    public Tracker() {
        map = new HashMap<>();
    }

    public Tracker(Map<String, Point> newMap) {
        map = cloneMap(newMap);
    }

    public synchronized void setLoc(String id, Point point) {
        map.put(id, point.clone());
    }

    public synchronized Point getLoc(String id) {
        return map.get(id).clone();
    }

    public synchronized Map<String, Point> getLocations() {
        return cloneMap(map);
    }

    private Map<String, Point> cloneMap(Map<String, Point> map) {
        Map<String, Point> cloneMap = new HashMap<>();
        for (String id : map.keySet()) {
            cloneMap.put(id, map.get(id).clone());
        }
        return cloneMap;
    }
}
